package com.itheima.accountingdb.controller;

import com.itheima.accountingdb.pojo.Result;
import com.itheima.accountingdb.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author panweiwei
 */
@RestController
@CrossOrigin
@RequestMapping("/reports")
public class ReportController {
    @Autowired
    private ReportService reportService;

    /**
     * 获取汇总报表
     * @param userId
     * @param startDate
     * @param endDate
     * @param categoryId
     * @return
     */
    @GetMapping("/summary")
    public Result<Map<String, Object>> getSummaryReport(
            @RequestParam Long userId,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate,
            @RequestParam(required = false) Integer categoryId
    ) {
        Map<String, Object> summary = reportService.getSummaryReport(userId, startDate, endDate, categoryId);
        return Result.success(summary);
    }


    /**
     * 获取图表数据
     * @param startDate
     * @param endDate
     * @param type
     * @return
     */
    @GetMapping("/chart")
    public Result<Map<String, Object>> getChartData(
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate,
            @RequestParam(defaultValue = "day") String type) {

        Map<String, Object> chartData = reportService.getChartData(startDate, endDate, type);
        return Result.success(chartData);
    }
}
